package day03;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.IOException;

public class HadoopAPI {

    public static void main(String[] args) throws IOException {

        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);

        FSDataInputStream fsin = fs.open(new Path("E:\\a.txt"));

        int length = 0;
        byte[] buff = new byte[128];
        while ((length = fsin.read(buff, 0 ,128)) != -1){
            System.out.println(new String(buff));
        }

        System.out.println(fsin.getPos());
        IOUtils.closeStream(fsin);


        FSDataOutputStream fsout = fs.create(new Path("E:\\a2.txt"));
        fsout.write("hahaha".getBytes());
        IOUtils.closeStream(fsout);






    }


}
